package picol.model.asa.inst;

import picol.model.asa.ASAVariable;
import picol.model.asa.expr.ASAExpr;
import picol.model.asa.expr.ASAExprEntier;

/**
 * Classe de gestion de l'instruction declaration
 * @author Aurélien Marcel - Julien Sanderson
 */
public class ASAInstDeclaration extends ASAInst {

    private ASAVariable var;

    public ASAInstDeclaration(ASAVariable _var) {
        this.var = _var;
    }

    @Override
    public void executer() {
        ASAExpr expr = this.var.getExpr();
        //Si la variable a ete initialisee
        if (expr != null) {
            int evalue = expr.evalue();

            ASAInstPicoL.addVariable(var);
            ASAInstPicoL.modifierVar(this.var.getDeclaration().getIdent(), new ASAExprEntier(evalue));
        } else {
            ASAInstPicoL.addVariable(var);
        }
    }

    @Override
    public boolean executerDebug() {
        ASAExpr expr = this.var.getExpr();
        //Si la variable a ete initialisee
        if (expr != null) {
            int evalue = expr.evalue();

            ASAInstPicoL.addVariable(var);
            ASAInstPicoL.modifierVar(this.var.getDeclaration().getIdent(), new ASAExprEntier(evalue));
        } else {
            ASAInstPicoL.addVariable(var);
        }
        return true;
    }

    @Override
    public int getNbInst() {
        return 0;
    }
}
